package com.jiangyao.controller;

import com.github.pagehelper.PageInfo;
import com.jiangyao.common.ApiResult;
import com.jiangyao.common.exception.ServerException;
import com.jiangyao.model.dto.DeliverDTO;
import com.jiangyao.model.dto.JobDTO;
import com.jiangyao.model.entity.Category;
import com.jiangyao.model.vo.JobVo;
import com.jiangyao.model.vo.SendResumeVo;
import com.jiangyao.service.CategoryService;
import com.jiangyao.service.JobDataService;
import com.jiangyao.service.JobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhousx
 * @create 2020/8/12
 */

@RestController
@RequestMapping("/job")
@Api(tags = "职位相关接口")
public class JobController extends BaseController{

    @Autowired
    private JobService jobService;

    @Autowired
    private CategoryService categoryService;


    @Autowired
    private JobDataService jobDataService;

    @PostMapping("/getJobCategory")
    @ApiOperation(value = "获取招聘分类")
    public ApiResult<Category> getJobCategory(){
        return new ApiResult(categoryService.getJobCategory());
    }

    /**
     * 获取首页招聘展示
     * @return
     */
    @PostMapping("/getWebJobList")
    @ApiOperation(value = "获取招聘列表")
    public ApiResult<PageInfo> getWebJobList(@RequestBody JobDTO jobDTO){
        return new ApiResult(jobService.getWebJobList(jobDTO));
    }

    /**
     * 获取职位详情
     * @param jobDTO
     * @return
     */
    @PostMapping("/lookJobDetail")
    @ApiOperation(value = "新增查看数",notes="必传jobId")
    public ApiResult<Boolean> lookJobDetail(@RequestBody JobDTO jobDTO){
        return ApiResult.success(jobDataService.addViewNum(jobDTO.getJobId()));
    }


    /**
     * 获取职位详情
     * @param jobDTO
     * @return
     */
    @PostMapping("/getJobDetail")
    @ApiOperation(value = "获取职位详情")
    public ApiResult<JobVo> getJobDetail(@RequestBody JobDTO jobDTO){
        return ApiResult.success(jobService.getJobDetail(jobDTO.getJobId()));
    }


    /**
     * 获取投递职位
     * @param deliverDTO
     * @return
     */
    @PostMapping("/getResumeSuccess")
    @ApiOperation(value = "获取投递成功的简历",notes = "必填字段deliveryStatus：投递状态  0为投递成功   1为已被查看   2为已邀请面试")
    public ApiResult<List<SendResumeVo>> getResumeSuccess(@RequestBody DeliverDTO deliverDTO){
        try {
            List<SendResumeVo> resumeSuccess = jobService.getResumeSuccess(deliverDTO);
            return ApiResult.success(resumeSuccess);
        } catch (ServerException e) {
            return ApiResult.success(e.getMessage());
        }
    }
}
